package fun.taostool.service.taost.impl;

import lombok.SneakyThrows;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test {

    @SneakyThrows
    public static void main(String[] args) {
//         String createTableStatement = "CREATE STABLE `tag_st` (`ts` TIMESTAMP, `value` FLOAT, `aste` FLOAT, `qul` FLOAT) TAGS (`euId` FLOAT, `ecId` FLOAT, `locationCode` NCHAR(200), `tagName` NCHAR(64))";
//         String createTableStatement = "CREATE STABLE `battery_rate` (`ts` TIMESTAMP, `u_value` FLOAT, `t_value` FLOAT, `t_rate` FLOAT, `u_rate` FLOAT, `charge_state` INT, `ischange` INT) TAGS (`euId` FLOAT, `ecId` FLOAT, `clusterLocationCode` NCHAR(200), `BMSLocationCode` NCHAR(200))";
//         String createTableStatement = "CREATE STABLE `battery` (`ts` TIMESTAMP, `u_value` FLOAT, `t_value` FLOAT, `u_qul` FLOAT, `t_qul` FLOAT) TAGS (`euId` FLOAT, `ecId` FLOAT, `locationCode` NCHAR(200))";
//         String createTableStatement = "CREATE STABLE `plan_mon_reality` (`ts` TIMESTAMP, `relative_ts` TIMESTAMP, `P` FLOAT, `PSet` FLOAT, `CtlSta` INT, `control_id` INT, `item_id` INT, `plan_state` INT, `predict_state` INT, `level` INT, `remark` NCHAR(50)) TAGS (`locationCode` NCHAR(200))";
//        String createTableStatement = "CREATE STABLE `plan_mon_predict` (`ts` TIMESTAMP, `relative_ts` TIMESTAMP, `P` FLOAT, `PSet` FLOAT, `CtlSta` INT, `control_id` INT, `item_id` INT, `remark` NCHAR(50)) TAGS (`locationCode` NCHAR(200))";
//        String createTableStatement = "CREATE STABLE `tag_st` (`ts` TIMESTAMP ENCODE 'delta-i' COMPRESS 'lz4' LEVEL 'medium', `value` FLOAT ENCODE 'delta-d' COMPRESS 'lz4' LEVEL 'medium', `aste` FLOAT ENCODE 'delta-d' COMPRESS 'lz4' LEVEL 'medium', `qul` FLOAT ENCODE 'delta-d' COMPRESS 'lz4' LEVEL 'medium') TAGS (`euId` FLOAT, `ecId` FLOAT, `locationCode` NCHAR(200), `tagName` NCHAR(64))";
//        // 解析建表语句并创建Avro schema JSON对象
//        JSONObject avroSchema = parseCreateTableStatement(createTableStatement);
//
//        // 打印Avro schema JSON
//        System.out.println(avroSchema.toString(4));
        String originalString = "EU4_EPEpkt";
//        String originalString = "EU1-PWC2-CT1-PCS(m)4-PCSMG1_RetHum";
//        String originalString = "EU1-PWC2-CT1-PCS(m)4_RetHum";
//        String originalString = "EU21-LVC1-BMM1_EPIvlt";

        String[] parts = originalString.split("[-_]");

        String part = "";
        // 检查分割后的数组长度是否足够
        if (parts.length >= 3) {
            // 取倒数第二个元素，因为最后一个-和_之间的部分在分割后会是倒数第二个元素
            part = parts[parts.length - 2];
        } else if (parts.length == 2) {
            part = parts[0];
        } else {
            System.out.println("字符串格式不正确，无法提取所需部分");
        }

        // 定义正则表达式，匹配由一个或多个连续字母组成的字符串
        String regex = "[A-Za-z]+(\\([A-Za-z]+\\))?";

        // 编译正则表达式
        Pattern pattern = Pattern.compile(regex);

        Matcher matcher = pattern.matcher(part);
        while (matcher.find()) {
            System.out.println("从\"" + part + "\"中提取到:\"" + matcher.group() + "\"");
        }

    }
}
